﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;
using FrameworkManapro.Utilities;
using FrameworkManapro.WebUI;


namespace GMAC.ReportingSystem.Business.Components
{
    public class CallingIVRComponent : IBusinessComponent<Entities.CallingIVR>
    {
        private DataAccess.CallingIVRDataAccess dac;

        public CallingIVRComponent()
        {
            dac = new DataAccess.CallingIVRDataAccess();
        }

        #region IBusinessComponent<CallingIVR> Members

        public int Create(Entities.CallingIVR entityToCreate)
        {
            if (Validate(entityToCreate))
            {
                var result = dac.Insert(entityToCreate);
                return result;
            }
            return 0;
        }

        public int Delete(Entities.CallingIVR entityToDelete)
        {
            if (entityToDelete.ID <= 0)
                throw new ArgumentOutOfRangeException("ID", "Value must be greater than zero.");

            return dac.Delete(entityToDelete);
        }

        public int Edit(Entities.CallingIVR entityToEdit)
        {
            if (entityToEdit.ID <= 0)
                throw new ArgumentOutOfRangeException("ID", "Value must be greater than zero.");

            return Validate(entityToEdit) ? dac.Update(entityToEdit) : 0;
        }

        public Entities.CallingIVR GetDetails(object entityId)
        {
            return dac.Get(entityId);
        }

        protected bool Validate(Entities.CallingIVR CallingIVR)
        {
            if (CallingIVR == null) throw new ArgumentNullException("CallingIVR", "The argument cannot be null.");
            if (string.IsNullOrEmpty(CallingIVR.DateCall.ToString())) throw new ArgumentNullException("DateCall", "The argument cannot be null.");
            if (string.IsNullOrEmpty(CallingIVR.Calls.ToString())) throw new ArgumentNullException("Calls", "The argument cannot be null.");
            return true;
        }

        #endregion


        public Entities.CallingIVRCollection GetList()
        {
            return dac.GetList();
        }

        public Entities.CallingIVRCollection Search(DateTime? DateCall, PagingDetails paging)
        {
            return dac.Search(DateCall,  paging);
        }

    }
}
